package com.itheima.Interceptor;



import com.alibaba.fastjson.JSONObject;
import com.itheima.Utils.JwtUtils;
import com.itheima.pojo.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.http.parser.Authorization;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import java.awt.desktop.PreferencesHandler;
import java.io.IOException;
import java.util.Map;

@Component
public class LoginCheckInterceptor implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token=request.getHeader("Authorization");

        System.out.println("进入拦截器");
        System.out.println(token);
        try{
            Map<String,Object>claims=JwtUtils.parseJwt(token);
            System.out.println("携带啦令牌");
            return true;
        }catch (Exception e){
            System.out.println("未携带令牌");
            response.setStatus(401);
            return false;
        }

    }
}
